package com.atguigu.tingshu.album.config;



import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 创建交换机、队列、绑定
 */
@Configuration
public class AlbumRaabitConfig {

    //创建交换机
    @Bean("albumExchange")
    public Exchange albumExchange(){
        return ExchangeBuilder.directExchange("albuminfo_exchange").build();
    }
    //创建上架队列
    @Bean("alubmUpQueue")
    public Queue alubmUpQueue(){
        return QueueBuilder.durable("albumIinfo_up_queue").build();
    }
    //创建下架队列
    @Bean("alubmDownQueue")
    public Queue alubmDownQueue(){
        return QueueBuilder.durable("albumIinfo_down_queue").build();
    }

    //上架动态绑定
    @Bean
    public Binding alubmUpQueueBinding(@Qualifier(value = "alubmUpQueue") Queue alubmUpQueue,
                                       @Qualifier(value = "albumExchange") Exchange albumExchange){
        return BindingBuilder.bind(alubmUpQueue).to(albumExchange).with("album.es.upper").noargs();
    }
    //下架动态绑定
    @Bean
    public Binding alubmDownQueueBinding(@Qualifier(value = "alubmDownQueue") Queue alubmDownQueue,
                                         @Qualifier(value = "albumExchange") Exchange albumExchange){
        return BindingBuilder.bind(alubmDownQueue).to(albumExchange).with("album.es.down").noargs();
    }
}
